#随机⽣成20个[1, 20]的正整数，统计每个数字出现的次数，排序并降序输出次数最多的前三个数字及次数

import random
lst = random.choices(list(range(1, 21)), k=20)
sorted_lst = sorted(lst)
new_list = list()

def counter(i):
    while i == 20:
        return 1
    step = 0
    count = 0
    num = sorted_lst[i]
    count = sorted_lst.count(sorted_lst[i])
    step = count + i
    str1 = '数字{}: 出现{}次'.format(num, count)
    new_list.append(str1)
    step = counter(step)

counter(0)
print("随机数序列：",sorted_lst)
print('出现个数排序：',new_list)
l1 = (sorted(new_list,key=lambda x:x.split('现')[1],reverse=True))
print('出现次数最多的三个数字：',l1[0],' ',l1[2],' ',l1[2])


# 做的不错
